package com.example.multitenant.multitenant.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import java.util.concurrent.Executor

/**
 *
 * Author: Gao Xiang
 * Create: 2020/12/26
 * Description:
 *
 **/

@Configuration
class ExecutorConfig {

    companion object{
        private const val TAG = "ExecutorConfig"
    }

    @Bean
    fun taskExecutor(): Executor {
        val executor = ThreadPoolTaskExecutor()
        executor.corePoolSize = 80     // 80个线程，每秒能处理800个任务(一个任务100ms)
        executor.maxPoolSize = 280     // 额外200个线程，每秒最多能处理2800个任务，多了只能拒绝
        executor.queueCapacity = 400   // 400个排队，每个任务最多等待500ms
        executor.setThreadNamePrefix("my-executor-")
        executor.initialize()
        return executor
    }

}